﻿<html>

<head>
</head>

<body>
<h1>Edição de Comentarios</h1>
	<table border="1">
		<tr>
			<th>Titulo Post</th>
			<th>Total de Coment.</th>
			<th>Ação</th>
		</tr>
		
		<?php
			
			$totalComentarios = 0;
		
			$xml = new DomDocument();
			$xml->load('../blog.xml');
			
			$posts 		= $xml->getElementsByTagName('post');
			$comentario = $xml->getElementsByTagName('comentario');
			
			foreach($posts as $post){
				$idPost = $post->getAttribute('idPost');
				foreach($comentario as $coment){
					$idPostComentario = $coment->getAttribute('idPostComentario');
					if($idPostComentario == $idPost){
						$totalComentarios++; 
					}else{
						$totalComentarios = 0;
					}
				}
				$titulo = $post->getElementsByTagName('titulo')->item(0)->nodeValue;
				
				echo "<tr>
						  <td>{$titulo}</td>
						  <td>{$totalComentarios}</td>
						  <td><a href=\"alterarComentario.php?idPost={$idPost}\">Visualizar/Editar</a></td>
					  </tr>";
			}
			
		?>
		
	</table>
	<a href="index.php">Voltar</a>
</body>

</html>